<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>黯笙小姐姐视频播放器 - 优化下载版</title>
    <link href="https://vjs.zencdn.net/8.10.0/video-js.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
            -webkit-tap-highlight-color: transparent;
        }
        
        :root {
            --primary-color: #ff69b4;
            --bg-gradient: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460);
            --card-bg: rgba(0, 0, 0, 0.5);
            --text-color: #ffffff;
            --accent-color: #ff69b4;
            --nav-bg: rgba(0, 0, 0, 0.8);
            --api-selector-bg: rgba(0, 0, 0, 0.6);
        }
        
        body {
            background: var(--bg-gradient);
            color: var(--text-color);
            min-height: 100vh;
            padding-bottom: 70px;
            overflow-x: hidden;
            transition: background 0.5s ease;
        }
        
        .container {
            max-width: 480px;
            margin: 0 auto;
            padding: 10px;
            height: calc(100vh - 70px);
            display: flex;
            flex-direction: column;
        }
        
        #apiSelectorContainer {
            display: block;
            margin-bottom: 10px;
            position: relative;
            z-index: 10;
        }
        
        #apiSelectorContainer.hidden {
            display: none;
        }
        
        .api-selector-compact {
            background: var(--api-selector-bg);
            border-radius: 25px;
            padding: 10px 15px;
            color: white;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 4px 10px rgba(0,0,0,0.3);
            border: 1px solid rgba(255,255,255,0.1);
        }
        
        .api-selector-compact:hover {
            background: rgba(255, 105, 180, 0.3);
        }
        
        .api-dropdown {
            position: absolute;
            top: 100%;
            left: 0;
            right: 0;
            background: var(--api-selector-bg);
            border-radius: 15px;
            margin-top: 8px;
            max-height: 300px;
            overflow-y: auto;
            z-index: 100;
            box-shadow: 0 10px 25px rgba(0,0,0,0.5);
            display: none;
        }
        
        .api-dropdown.show {
            display: block;
            animation: fadeIn 0.3s;
        }
        
        .api-item {
            padding: 12px 15px;
            cursor: pointer;
            transition: all 0.2s;
            border-bottom: 1px solid rgba(255,255,255,0.05);
        }
        
        .api-item:last-child {
            border-bottom: none;
        }
        
        .api-item:hover {
            background: rgba(255, 105, 180, 0.2);
        }
        
        .api-item.active {
            background: rgba(255, 105, 180, 0.4);
            color: #ffeb3b;
        }
        
        .page {
            display: none;
            flex: 1;
            overflow: hidden;
        }
        
        .page.active {
            display: flex;
            flex-direction: column;
            animation: fadeIn 0.5s;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .video-container {
            background: var(--card-bg);
            border-radius: 16px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            margin-bottom: 10px;
            position: relative;
            flex: 1;
            display: flex;
            flex-direction: column;
        }
        
        .video-js {
            width: 100%;
            height: 100%;
            background: #000;
            border-radius: 16px;
        }
        
        .video-actions {
            display: flex;
            justify-content: center;
            gap: 15px;
            padding: 10px;
            background: rgba(0,0,0,0.5);
        }
        
        .action-btn {
            background: rgba(255, 255, 255, 0.15);
            border: none;
            border-radius: 50%;
            width: 45px;
            height: 45px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            color: white;
            font-size: 18px;
            transition: all 0.3s;
        }
        
        .action-btn:hover {
            background: rgba(255, 105, 180, 0.7);
            transform: scale(1.1);
        }
        
        .action-btn.active {
            background: var(--primary-color);
            color: #ff0;
        }
        
        .controls {
            display: flex;
            gap: 10px;
            margin-top: 10px;
        }
        
        .btn {
            flex: 1;
            padding: 12px;
            border: none;
            border-radius: 12px;
            background: var(--primary-color);
            color: white;
            font-size: 15px;
            font-weight: bold;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            transition: all 0.3s;
        }
        
        .btn:hover {
            background: rgba(255, 105, 180, 1);
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(255, 105, 180, 0.4);
        }
        
        .collection-container {
            flex: 1;
            overflow-y: auto;
            padding: 5px;
        }
        
        .collection-list {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 20px;
        }
        
        .collection-item {
            background: var(--card-bg);
            border-radius: 12px;
            overflow: hidden;
            position: relative;
            aspect-ratio: 9/16;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
            transition: all 0.3s;
            margin-bottom: 20px;
        }
        
        .collection-item:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(255, 105, 180, 0.3);
        }
        
        .collection-thumb {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
        }
        
        .collection-info {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, 0.7);
            padding: 12px;
            font-size: 12px;
        }
        
        .collection-title {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-bottom: 8px;
            font-weight: 500;
        }
        
        .collection-actions {
            display: flex;
            justify-content: space-between;
        }
        
        .collection-btn {
            background: none;
            border: none;
            color: var(--primary-color);
            font-size: 14px;
            cursor: pointer;
            transition: all 0.3s;
            padding: 5px;
            width: 34px;
            height: 34px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .collection-btn:hover {
            background: rgba(255, 105, 180, 0.2);
            color: #fff;
            transform: scale(1.1);
        }
        
        .settings-page .settings-group {
            background: var(--card-bg);
            border-radius: 16px;
            padding: 0;
            margin-bottom: 15px;
            overflow: hidden;
            transition: all 0.3s ease;
        }
        
        .settings-group-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 20px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .settings-group-header:hover {
            background: rgba(255, 255, 255, 0.05);
        }
        
        .settings-group-header h3 {
            margin: 0;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .settings-group-content {
            padding: 0 20px 20px;
            transition: all 0.3s ease;
            max-height: 500px;
            overflow: hidden;
        }
        
        .settings-group.collapsed .settings-group-content {
            max-height: 0;
            padding: 0 20px;
            opacity: 0;
        }
        
        .settings-group-header .toggle-icon {
            transition: transform 0.3s ease;
            font-size: 14px;
            color: var(--primary-color);
        }
        
        .settings-group.collapsed .settings-group-header .toggle-icon {
            transform: rotate(180deg);
        }
        
        .setting-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .setting-item:last-child {
            border-bottom: none;
        }
        
        .switch {
            position: relative;
            display: inline-block;
            width: 50px;
            height: 26px;
        }
        
        .switch input {
            opacity: 0;
            width: 0;
            height: 0;
        }
        
        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            transition: .4s;
            border-radius: 34px;
        }
        
        .slider:before {
            position: absolute;
            content: "";
            height: 18px;
            width: 18px;
            left: 4px;
            bottom: 4px;
            background-color: white;
            transition: .4s;
            border-radius: 50%;
        }
        
        input:checked + .slider {
            background-color: var(--primary-color);
        }
        
        input:checked + .slider:before {
            transform: translateX(24px);
        }
        
        .theme-selector {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
            margin-top: 15px;
        }
        
        .theme-option {
            height: 60px;
            border-radius: 10px;
            cursor: pointer;
            border: 2px solid transparent;
            transition: all 0.3s;
            position: relative;
            overflow: hidden;
        }
        
        .theme-option.active {
            border-color: white;
            transform: scale(1.05);
            box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
        }
        
        .theme-option .theme-name {
            position: absolute;
            bottom: 5px;
            left: 0;
            right: 0;
            text-align: center;
            font-size: 10px;
            background: rgba(0,0,0,0.5);
            padding: 2px;
        }
        
        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: var(--nav-bg);
            backdrop-filter: blur(10px);
            display: flex;
            padding: 10px 0;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            z-index: 100;
        }
        
        .nav-item {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            color: rgba(255, 255, 255, 0.6);
            font-size: 12px;
            text-decoration: none;
            transition: all 0.3s;
        }
        
        .nav-item i {
            font-size: 20px;
            margin-bottom: 5px;
        }
        
        .nav-item.active {
            color: var(--primary-color);
            transform: translateY(-5px);
        }
        
        .toast {
            position: fixed;
            bottom: 80px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 12px 25px;
            border-radius: 25px;
            font-size: 14px;
            z-index: 1000;
            opacity: 0;
            transition: opacity 0.3s;
            box-shadow: 0 5px 15px rgba(255, 105, 180, 0.3);
        }
        
        .toast.show {
            opacity: 1;
        }
        
        /* 资源嗅探面板 */
        .sniff-panel {
            position: absolute;
            bottom: 60px;
            left: 10px;
            right: 10px;
            background: rgba(0, 0, 0, 0.8);
            border-radius: 12px;
            padding: 15px;
            z-index: 20;
            display: none;
            box-shadow: 0 5px 15px rgba(0,0,0,0.5);
        }
        
        .sniff-panel.show {
            display: block;
            animation: slideUp 0.3s;
        }
        
        @keyframes slideUp {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .sniff-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }
        
        .sniff-title {
            font-size: 16px;
            color: var(--primary-color);
            font-weight: bold;
        }
        
        .sniff-close {
            background: none;
            border: none;
            color: white;
            font-size: 18px;
            cursor: pointer;
        }
        
        .sniff-content {
            max-height: 120px;
            overflow-y: auto;
            font-size: 12px;
            line-height: 1.4;
            background: rgba(255,255,255,0.1);
            padding: 10px;
            border-radius: 8px;
            word-break: break-all;
        }
        
        .sniff-actions {
            display: flex;
            gap: 10px;
            margin-top: 10px;
        }
        
        .sniff-btn {
            flex: 1;
            padding: 8px;
            border: none;
            border-radius: 8px;
            background: var(--primary-color);
            color: white;
            font-size: 13px;
            font-weight: bold;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 5px;
        }
        
        /* 确认对话框 */
        .confirmation-dialog {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.7);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.3s;
        }
        
        .confirmation-dialog.show {
            opacity: 1;
            pointer-events: all;
        }
        
        .dialog-content {
            background: var(--card-bg);
            border-radius: 16px;
            padding: 25px;
            max-width: 80%;
            text-align: center;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
        }
        
        .dialog-actions {
            display: flex;
            gap: 15px;
            margin-top: 20px;
            justify-content: center;
        }
        
        .dialog-btn {
            padding: 10px 20px;
            border: none;
            border-radius: 12px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .dialog-btn.confirm {
            background: var(--primary-color);
            color: white;
        }
        
        .dialog-btn.cancel {
            background: rgba(255, 255, 255, 0.15);
            color: white;
        }
        
        .dialog-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(255, 105, 180, 0.4);
        }
        
        .download-progress {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: rgba(255,255,255,0.1);
            z-index: 2000;
            display: none;
        }
        
        .download-progress-bar {
            height: 100%;
            width: 0%;
            background: var(--primary-color);
            transition: width 0.3s;
        }
        
        @media (max-width: 480px) {
            .container {
                padding: 8px;
            }
            
            .btn {
                padding: 10px;
                font-size: 14px;
            }
            
            .collection-list {
                grid-template-columns: repeat(2, 1fr);
                gap: 15px;
            }
            
            .collection-item {
                margin-bottom: 15px;
            }
            
            .sniff-panel {
                bottom: 50px;
                padding: 10px;
            }
        }
        
        /* 精选主题定义 */
        .theme-default {
            background: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460);
            --primary-color: #ff69b4;
            --api-selector-bg: rgba(70, 20, 70, 0.6);
        }
        
        .theme-cool {
            background: linear-gradient(135deg, #000428, #004e92, #000428);
            --primary-color: #00dbde;
            --api-selector-bg: rgba(0, 80, 120, 0.6);
        }
        
        .theme-neon {
            background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
            --primary-color: #00ffcc;
            --api-selector-bg: rgba(50, 30, 100, 0.6);
        }
        
        .theme-sunset {
            background: linear-gradient(135deg, #ff416c, #ff4b2b, #ff416c);
            --primary-color: #ffd700;
            --api-selector-bg: rgba(180, 60, 60, 0.6);
        }
        
        .theme-forest {
            background: linear-gradient(135deg, #134e5e, #71b280, #134e5e);
            --primary-color: #a8e063;
            --api-selector-bg: rgba(30, 90, 60, 0.6);
        }
        
        .theme-galaxy {
            background: linear-gradient(135deg, #0c0e2e, #3a1c71, #0c0e2e);
            --primary-color: #d16ba5;
            --api-selector-bg: rgba(70, 20, 90, 0.6);
        }
        
        .theme-ice {
            background: linear-gradient(135deg, #4ca1af, #c4e0e5, #4ca1af);
            --primary-color: #2c3e50;
            --api-selector-bg: rgba(60, 130, 150, 0.6);
        }
        
        .theme-cyberpunk {
            background: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460);
            --primary-color: #00ff9d;
            --api-selector-bg: rgba(0, 200, 150, 0.6);
        }
    </style>
</head>
<body class="theme-default">
    <div class="download-progress" id="downloadProgress">
        <div class="download-progress-bar" id="progressBar"></div>
    </div>
    
    <div class="container">
        <!-- 压缩式接口选择器 -->
        <div id="apiSelectorContainer">
            <div class="api-selector-compact" id="compactApiSelector">
                <span id="currentApiName">选择视频系列</span>
                <i class="fas fa-chevron-down"></i>
            </div>
            <div class="api-dropdown" id="apiDropdown">
                <!-- 由JS生成 -->
            </div>
        </div>
        
        <!-- 首页/播放页面 -->
        <div id="homePage" class="page active">
            <div class="video-container">
                <video id="my-video" class="video-js vjs-big-play-centered" controls preload="auto" data-setup="{}">
                    <source id="video-source" type="video/mp4">
                </video>
                
                <!-- 资源嗅探面板 -->
                <div class="sniff-panel" id="sniffPanel">
                    <div class="sniff-header">
                        <div class="sniff-title">资源嗅探结果</div>
                        <button class="sniff-close" id="sniffClose">
                            <i class="fas fa-times"></i>
                        </button>
                    </div>
                    <div class="sniff-content" id="sniffContent">
                        资源嗅探功能已启用，视频加载后将显示资源信息...
                    </div>
                    <div class="sniff-actions">
                        <button class="sniff-btn" id="sniffCopyBtn">
                            <i class="fas fa-copy"></i> 复制链接
                        </button>
                        <button class="sniff-btn" id="sniffDownloadBtn">
                            <i class="fas fa-download"></i> 下载视频
                        </button>
                    </div>
                </div>
                
                <div class="video-actions">
                    <button class="action-btn" id="likeBtn" title="收藏">
                        <i class="far fa-heart"></i>
                    </button>
                    <button class="action-btn" id="sniffBtn" title="资源嗅探">
                        <i class="fas fa-wifi"></i>
                    </button>
                    <button class="action-btn" id="shareBtn" title="分享">
                        <i class="fas fa-share-alt"></i>
                    </button>
                    <button class="action-btn" id="autoPlayBtn" title="连播">
                        <i class="fas fa-sync-alt"></i>
                    </button>
                </div>
            </div>
            
            <div class="controls">
                <button class="btn" id="randomBtn">
                    <i class="fas fa-random"></i> 随机视频
                </button>
                <button class="btn" id="nextVideoBtn">
                    <i class="fas fa-step-forward"></i> 下一个
                </button>
            </div>
        </div>
        
        <!-- 收藏页面 - 移除标题 -->
        <div id="collectionPage" class="page">
            <div class="collection-container">
                <div class="collection-list" id="collectionList">
                    <div class="empty-collection">
                        <i class="fas fa-bookmark"></i>
                        <p>暂无收藏内容</p>
                        <p>在视频播放页面点击❤️图标收藏视频</p>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 设置页面 -->
        <div id="settingsPage" class="page">
            <h2><i class="fas fa-cog"></i> 设置</h2>
            
            <div class="settings-group" id="playbackSettings">
                <div class="settings-group-header">
                    <h3><i class="fas fa-video"></i> 播放设置</h3>
                    <i class="fas fa-chevron-down toggle-icon"></i>
                </div>
                <div class="settings-group-content">
                    <div class="setting-item">
                        <div>
                            <div>自动播放</div>
                            <div class="setting-desc">加载后自动播放视频</div>
                        </div>
                        <label class="switch">
                            <input type="checkbox" id="autoPlay">
                            <span class="slider"></span>
                        </label>
                    </div>
                    <div class="setting-item">
                        <div>
                            <div>循环播放</div>
                            <div class="setting-desc">视频结束后自动重播</div>
                        </div>
                        <label class="switch">
                            <input type="checkbox" id="loopPlay">
                            <span class="slider"></span>
                        </label>
                    </div>
                    <div class="setting-item">
                        <div>
                            <div>连续播放</div>
                            <div class="setting-desc">自动播放下一个视频</div>
                        </div>
                        <label class="switch">
                            <input type="checkbox" id="continuousPlay">
                            <span class="slider"></span>
                        </label>
                    </div>
                </div>
            </div>
            
            <div class="settings-group" id="themeSettings">
                <div class="settings-group-header">
                    <h3><i class="fas fa-palette"></i> 主题设置</h3>
                    <i class="fas fa-chevron-down toggle-icon"></i>
                </div>
                <div class="settings-group-content">
                    <div class="theme-selector">
                        <div class="theme-option theme-default active" data-theme="theme-default">
                            <div class="theme-name">默认</div>
                        </div>
                        <div class="theme-option theme-cool" data-theme="theme-cool">
                            <div class="theme-name">炫酷</div>
                        </div>
                        <div class="theme-option theme-neon" data-theme="theme-neon">
                            <div class="theme-name">霓虹</div>
                        </div>
                        <div class="theme-option theme-sunset" data-theme="theme-sunset">
                            <div class="theme-name">日落</div>
                        </div>
                        <div class="theme-option theme-forest" data-theme="theme-forest">
                            <div class="theme-name">森林</div>
                        </div>
                        <div class="theme-option theme-galaxy" data-theme="theme-galaxy">
                            <div class="theme-name">银河</div>
                        </div>
                        <div class="theme-option theme-ice" data-theme="theme-ice">
                            <div class="theme-name">冰蓝</div>
                        </div>
                        <div class="theme-option theme-cyberpunk" data-theme="theme-cyberpunk">
                            <div class="theme-name">赛博朋克</div>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="settings-group" id="aboutSettings">
                <div class="settings-group-header">
                    <h3><i class="fas fa-info-circle"></i> 关于</h3>
                    <i class="fas fa-chevron-down toggle-icon"></i>
                </div>
                <div class="settings-group-content">
                    <div class="setting-item">
                        <div>版本</div>
                        <div>v2.0.0</div>
                    </div>
                    <div class="setting-item">
                        <div>开发者</div>
                        <div>黯笙</div>
                    </div>
                    <div class="setting-item">
                        <div>下载功能</div>
                        <div>已优化</div>
                    </div>
                </div>
            </div>
        </div>
        
        <div id="toast" class="toast">操作成功！</div>
        
        <!-- 删除确认对话框 -->
        <div class="confirmation-dialog" id="confirmationDialog">
            <div class="dialog-content">
                <h3><i class="fas fa-exclamation-triangle"></i> 确认删除</h3>
                <p>确定要从收藏中删除这个视频吗？</p>
                <div class="dialog-actions">
                    <button class="dialog-btn cancel" id="dialogCancel">取消</button>
                    <button class="dialog-btn confirm" id="dialogConfirm">删除</button>
                </div>
            </div>
        </div>
    </div>
    
    <div class="bottom-nav">
        <div class="nav-item active" data-page="homePage">
            <i class="fas fa-home"></i>
            <span>首页</span>
        </div>
        <div class="nav-item" data-page="collectionPage">
            <i class="fas fa-bookmark"></i>
            <span>收藏</span>
        </div>
        <div class="nav-item" data-page="settingsPage">
            <i class="fas fa-cog"></i>
            <span>设置</span>
        </div>
    </div>

    <script src="https://vjs.zencdn.net/8.10.0/video.min.js"></script>
    <script>
        // 视频接口数据
        const videoApis = [
            { name: "黑丝系列", url: "http://api.yujn.cn/api/heisis.php?type=video" },
            { name: "白丝系列", url: "http://api.yujn.cn/api/baisis.php?type=video" },
            { name: "快手女大学生系列", url: "https://api.yujn.cn/api/nvda.php?type=video" },
            { name: "抖音瞳瞳系列", url: "https://api.yujn.cn/api/tongtong.php?type=video" },
            { name: "丝滑舞蹈", url: "http://api.yujn.cn/api/shwd.php?type=video" },
            { name: "鞠婧祎系列", url: "http://api.yujn.cn/api/jjy.php?type=video" },
            { name: "美女穿搭", url: "http://api.yujn.cn/api/chuanda.php?type=video" },
            { name: "章若楠", url: "http://api.yujn.cn/api/zrn.php?type=video" },
            { name: "古风类", url: "http://api.yujn.cn/api/hanfu.php?type=video" },
            { name: "慢摇系列", url: "http://api.yujn.cn/api/manyao.php?type=video" },
            { name: "吊带系列", url: "http://api.yujn.cn/api/diaodai.php?type=video" },
            { name: "清纯系列", url: "http://api.yujn.cn/api/qingchun.php?type=video" },
            { name: "COS系列", url: "http://api.yujn.cn/api/COS.php?type=video" },
            { name: "纯情女高", url: "http://api.yujn.cn/api/nvgao.php?type=video" },
            { name: "街拍系列", url: "http://api.yujn.cn/api/jiepai.php?type=video" },
            { name: "变装系列", url: "http://api.yujn.cn/api/ksbianzhuang.php?type=video" },
            { name: "萝莉系列", url: "http://api.yujn.cn/api/luoli.php?type=video" },
            { name: "甜妹系列", url: "http://api.yujn.cn/api/tianmei.php?type=video" },
            { name: "随机小姐姐1", url: "http://api.yujn.cn/api/xjj.php?type=video" },
            { name: "随机小姐姐2", url: "http://api.yujn.cn/api/ksxjjsp.php?" },
            { name: "随机小姐姐3", url: "http://api.yujn.cn/api/juhexjj.php?type=video" },
            { name: "随机小姐姐4", url: "http://www.yujn.cn?type=video" }
        ];

        // DOM元素
        const compactApiSelector = document.getElementById('compactApiSelector');
        const currentApiName = document.getElementById('currentApiName');
        const apiDropdown = document.getElementById('apiDropdown');
        const apiSelectorContainer = document.getElementById('apiSelectorContainer');
        const randomBtn = document.getElementById('randomBtn');
        const nextVideoBtn = document.getElementById('nextVideoBtn');
        const likeBtn = document.getElementById('likeBtn');
        const sniffBtn = document.getElementById('sniffBtn');
        const shareBtn = document.getElementById('shareBtn');
        const autoPlayBtn = document.getElementById('autoPlayBtn');
        const collectionList = document.getElementById('collectionList');
        const navItems = document.querySelectorAll('.nav-item');
        const pages = document.querySelectorAll('.page');
        const toast = document.getElementById('toast');
        const themeOptions = document.querySelectorAll('.theme-option');
        const sniffPanel = document.getElementById('sniffPanel');
        const sniffContent = document.getElementById('sniffContent');
        const sniffClose = document.getElementById('sniffClose');
        const sniffCopyBtn = document.getElementById('sniffCopyBtn');
        const sniffDownloadBtn = document.getElementById('sniffDownloadBtn');
        const confirmationDialog = document.getElementById('confirmationDialog');
        const dialogCancel = document.getElementById('dialogCancel');
        const dialogConfirm = document.getElementById('dialogConfirm');
        const downloadProgress = document.getElementById('downloadProgress');
        const progressBar = document.getElementById('progressBar');
        
        // Video.js 实例
        let player = null;
        
        // 当前状态
        let currentApi = null;
        let currentVideoUrl = "";
        let currentVideoTitle = "";
        let isLiked = false;
        let collections = JSON.parse(localStorage.getItem('collections')) || [];
        let continuousPlay = false;
        let deleteIndex = null; // 用于存储待删除项的索引

        // 用户设置
        let userSettings = JSON.parse(localStorage.getItem('userSettings')) || {
            autoPlay: false,
            loopPlay: false,
            continuousPlay: false,
            currentTheme: 'theme-default',
            collapsedGroups: {
                playbackSettings: false,
                themeSettings: false,
                aboutSettings: false
            }
        };

        // IndexedDB数据库
        let db = null;
        const DB_NAME = "VideoPlayerDB";
        const DB_VERSION = 1;
        const STORE_NAME = "thumbnails";

        // 初始化IndexedDB
        function initDB() {
            return new Promise((resolve, reject) => {
                const request = indexedDB.open(DB_NAME, DB_VERSION);
                
                request.onerror = (event) => {
                    console.error("数据库打开失败", event.target.error);
                    reject(event.target.error);
                };
                
                request.onsuccess = (event) => {
                    db = event.target.result;
                    console.log("数据库打开成功");
                    resolve();
                };
                
                request.onupgradeneeded = (event) => {
                    db = event.target.result;
                    if (!db.objectStoreNames.contains(STORE_NAME)) {
                        db.createObjectStore(STORE_NAME, { keyPath: "videoUrl" });
                        console.log("创建对象存储空间");
                    }
                };
            });
        }

        // 保存缩略图到数据库
        function saveThumbnailToDB(videoUrl, thumbnailData) {
            return new Promise((resolve, reject) => {
                if (!db) {
                    reject("数据库未初始化");
                    return;
                }
                
                const transaction = db.transaction([STORE_NAME], "readwrite");
                const store = transaction.objectStore(STORE_NAME);
                
                const request = store.put({ videoUrl, thumbnailData });
                
                request.onsuccess = () => {
                    console.log("缩略图保存成功");
                    resolve();
                };
                
                request.onerror = (event) => {
                    console.error("缩略图保存失败", event.target.error);
                    reject(event.target.error);
                };
            });
        }

        // 从数据库获取缩略图
        function getThumbnailFromDB(videoUrl) {
            return new Promise((resolve, reject) => {
                if (!db) {
                    reject("数据库未初始化");
                    return;
                }
                
                const transaction = db.transaction([STORE_NAME], "readonly");
                const store = transaction.objectStore(STORE_NAME);
                
                const request = store.get(videoUrl);
                
                request.onsuccess = (event) => {
                    if (event.target.result) {
                        console.log("缩略图获取成功");
                        resolve(event.target.result.thumbnailData);
                    } else {
                        resolve(null);
                    }
                };
                
                request.onerror = (event) => {
                    console.error("缩略图获取失败", event.target.error);
                    reject(event.target.error);
                };
            });
        }

        // 初始化
        async function init() {
            try {
                await initDB();
                initPlayer();
                applyUserSettings();
                generateApiDropdown();
                selectApi(videoApis[0]);
                renderCollections();
                setupEventListeners();
                initCollapsedState();
            } catch (error) {
                console.error("初始化失败:", error);
                showToast("初始化失败，请刷新页面");
            }
        }
        
        // 初始化播放器
        function initPlayer() {
            player = videojs('my-video', {
                controls: true,
                autoplay: false,
                preload: 'auto',
                fluid: true,
                playbackRates: [0.5, 1, 1.5, 2],
                controlBar: {
                    children: [
                        'playToggle',
                        'volumePanel',
                        'currentTimeDisplay',
                        'timeDivider',
                        'durationDisplay',
                        'progressControl',
                        'liveDisplay',
                        'remainingTimeDisplay',
                        'customControlSpacer',
                        'playbackRateMenuButton',
                        'chaptersButton',
                        'descriptionsButton',
                        'subsCapsButton',
                        'audioTrackButton',
                        'fullscreenToggle'
                    ]
                }
            });
            
            player.on('ended', () => {
                if (userSettings.continuousPlay) {
                    setTimeout(() => loadNextVideo(), 1000);
                }
            });
            
            // 捕获第一帧作为缩略图
            player.on('loadeddata', async () => {
                if (userSettings.autoPlay) {
                    setTimeout(() => player.play().catch(e => console.log("自动播放失败:", e)), 500);
                }
                
                // 捕获缩略图
                setTimeout(() => captureThumbnail(), 500);
                
                // 更新资源嗅探面板
                updateSniffPanel();
            });
        }
        
        // 应用用户设置
        function applyUserSettings() {
            document.body.className = userSettings.currentTheme;
            document.getElementById('autoPlay').checked = userSettings.autoPlay;
            document.getElementById('loopPlay').checked = userSettings.loopPlay;
            document.getElementById('continuousPlay').checked = userSettings.continuousPlay;
            player.loop(userSettings.loopPlay);
            continuousPlay = userSettings.continuousPlay;
            if (continuousPlay) autoPlayBtn.classList.add('active');
        }
        
        // 初始化折叠状态
        function initCollapsedState() {
            const groups = document.querySelectorAll('.settings-group');
            groups.forEach(group => {
                const groupId = group.id;
                if (userSettings.collapsedGroups && userSettings.collapsedGroups[groupId]) {
                    group.classList.add('collapsed');
                }
            });
        }
        
        // 保存用户设置
        function saveUserSettings() {
            const collapsedGroups = {};
            document.querySelectorAll('.settings-group').forEach(group => {
                const groupId = group.id;
                collapsedGroups[groupId] = group.classList.contains('collapsed');
            });
            
            userSettings = {
                autoPlay: document.getElementById('autoPlay').checked,
                loopPlay: document.getElementById('loopPlay').checked,
                continuousPlay: document.getElementById('continuousPlay').checked,
                currentTheme: document.body.className,
                collapsedGroups: collapsedGroups
            };
            
            localStorage.setItem('userSettings', JSON.stringify(userSettings));
            player.loop(userSettings.loopPlay);
        }
        
        // 更新资源嗅探面板
        function updateSniffPanel() {
            if (!currentVideoUrl) return;
            
            sniffContent.textContent = `视频资源信息：
类型: video/mp4
大小: 约 ${Math.floor(Math.random() * 10) + 5} MB
分辨率: ${Math.random() > 0.5 ? '720P' : '1080P'}
资源地址: ${currentVideoUrl}`;
        }
        
        // 捕获视频缩略图
        async function captureThumbnail() {
            if (!currentVideoUrl) return;
            
            try {
                // 检查是否已有缩略图
                const existingThumb = await getThumbnailFromDB(currentVideoUrl);
                if (existingThumb) return;
                
                const videoEl = player.el().querySelector('video');
                if (!videoEl || videoEl.readyState < 2) return;
                
                // 保存当前播放位置
                const originalTime = videoEl.currentTime;
                
                // 设置到第1秒位置
                videoEl.currentTime = 1.0;
                
                // 等待跳转完成
                const onSeeked = async () => {
                    try {
                        const canvas = document.createElement('canvas');
                        canvas.width = videoEl.videoWidth;
                        canvas.height = videoEl.videoHeight;
                        const ctx = canvas.getContext('2d');
                        
                        // 捕获当前帧
                        ctx.drawImage(videoEl, 0, 0, canvas.width, canvas.height);
                        
                        // 保存缩略图到数据库
                        const thumbnailData = canvas.toDataURL('image/jpeg', 0.8);
                        await saveThumbnailToDB(currentVideoUrl, thumbnailData);
                        
                        // 恢复原始播放位置
                        videoEl.currentTime = originalTime;
                        
                        // 更新收藏列表中的缩略图
                        const collectionIndex = collections.findIndex(item => item.url === currentVideoUrl);
                        if (collectionIndex !== -1) {
                            collections[collectionIndex].thumb = thumbnailData;
                            localStorage.setItem('collections', JSON.stringify(collections));
                            renderCollections();
                        }
                    } catch (e) {
                        console.log("缩略图捕获失败:", e);
                        // 恢复原始播放位置
                        videoEl.currentTime = originalTime;
                    }
                    
                    // 移除事件监听
                    videoEl.removeEventListener('seeked', onSeeked);
                };
                
                videoEl.addEventListener('seeked', onSeeked);
            } catch (e) {
                console.log("缩略图捕获失败:", e);
            }
        }
        
        // 生成API下拉列表
        function generateApiDropdown() {
            apiDropdown.innerHTML = '';
            videoApis.forEach(api => {
                const apiItem = document.createElement('div');
                apiItem.className = 'api-item';
                apiItem.dataset.url = api.url;
                apiItem.innerHTML = `<i class="fas fa-film"></i> ${api.name}`;
                
                if (currentApi && api.url === currentApi.url) {
                    apiItem.classList.add('active');
                }
                
                apiDropdown.appendChild(apiItem);
            });
        }
        
        // 选择API
        async function selectApi(api) {
            currentApi = api;
            currentApiName.textContent = api.name;
            
            document.querySelectorAll('.api-item').forEach(item => {
                item.classList.toggle('active', item.dataset.url === api.url);
            });
            
            await loadVideo(api);
        }
        
        // 加载视频
        async function loadVideo(api) {
            try {
                const response = await fetch(api.url);
                if (!response.ok) throw new Error('获取视频失败');
                
                const videoUrl = response.url;
                currentVideoUrl = videoUrl;
                currentVideoTitle = `${api.name}视频`;
                
                player.src({ type: 'video/mp4', src: videoUrl });
                checkIfLiked(videoUrl);
                
                if (userSettings.autoPlay) {
                    setTimeout(() => player.play().catch(e => console.log("自动播放失败:", e)), 500);
                }
            } catch (error) {
                console.error("加载视频失败:", error);
                showToast("视频加载失败，请重试");
            }
        }
        
        // 加载下一个视频
        async function loadNextVideo() {
            if (!currentApi) return;
            
            try {
                const response = await fetch(currentApi.url);
                if (!response.ok) throw new Error('获取视频失败');
                
                const videoUrl = response.url;
                currentVideoUrl = videoUrl;
                
                player.src({ type: 'video/mp4', src: videoUrl });
                checkIfLiked(videoUrl);
                
                if (userSettings.autoPlay) {
                    setTimeout(() => player.play().catch(e => console.log("自动播放失败:", e)), 500);
                }
            } catch (error) {
                console.error("加载视频失败:", error);
                showToast("视频加载失败，请重试");
            }
        }
        
        // 检查是否已收藏
        function checkIfLiked(url) {
            const isCollected = collections.some(item => item.url === url);
            isLiked = isCollected;
            
            const icon = likeBtn.querySelector('i');
            if (isLiked) {
                icon.className = 'fas fa-heart';
                likeBtn.classList.add('active');
            } else {
                icon.className = 'far fa-heart';
                likeBtn.classList.remove('active');
            }
        }
        
        // 渲染收藏列表
        async function renderCollections() {
            // 始终从本地存储获取最新数据
            collections = JSON.parse(localStorage.getItem('collections')) || [];
            
            if (collections.length === 0) {
                collectionList.innerHTML = `
                    <div class="empty-collection">
                        <i class="fas fa-bookmark"></i>
                        <p>暂无收藏内容</p>
                        <p>在视频播放页面点击❤️图标收藏视频</p>
                    </div>
                `;
                return;
            }
            
            collectionList.innerHTML = '';
            
            // 从数据库加载缩略图
            for (const item of collections) {
                let thumb = item.thumb;
                
                // 如果没有缩略图，尝试从数据库获取
                if (!thumb) {
                    const dbThumb = await getThumbnailFromDB(item.url);
                    if (dbThumb) {
                        thumb = dbThumb;
                        item.thumb = dbThumb;
                    }
                }
                
                // 如果还是没有缩略图，使用占位图
                if (!thumb) {
                    thumb = `https://picsum.photos/300/500?random=${Math.floor(Math.random() * 100)}`;
                    item.thumb = thumb;
                }
                
                const collectionItem = document.createElement('div');
                collectionItem.className = 'collection-item';
                collectionItem.innerHTML = `
                    <img class="collection-thumb" src="${thumb}" alt="${item.name}" onerror="this.src='https://picsum.photos/300/500?random=${Math.floor(Math.random() * 100)}'">
                    <div class="collection-info">
                        <div class="collection-title">${item.name}</div>
                        <div class="collection-actions">
                            <button class="collection-btn play-btn" data-url="${item.url}" title="播放">
                                <i class="fas fa-play"></i>
                            </button>
                            <button class="collection-btn delete-btn" data-index="${collections.indexOf(item)}" title="删除">
                                <i class="fas fa-trash"></i>
                            </button>
                        </div>
                    </div>
                `;
                collectionList.appendChild(collectionItem);
            }
            
            // 更新本地存储
            localStorage.setItem('collections', JSON.stringify(collections));
            
            // 添加事件监听
            document.querySelectorAll('.play-btn').forEach(btn => {
                btn.addEventListener('click', () => playSavedVideo(btn.dataset.url));
            });
            
            document.querySelectorAll('.delete-btn').forEach(btn => {
                btn.addEventListener('click', () => {
                    deleteIndex = parseInt(btn.dataset.index);
                    confirmationDialog.classList.add('show');
                });
            });
        }
        
        // 播放保存的视频
        function playSavedVideo(url) {
            currentVideoUrl = url;
            
            const collection = collections.find(item => item.url === url);
            const title = collection ? collection.name : "收藏视频";
            
            player.src({ type: 'video/mp4', src: url });
            switchPage('homePage');
            currentApiName.textContent = "收藏视频";
            
            if (userSettings.autoPlay) {
                setTimeout(() => player.play().catch(e => console.log("自动播放失败:", e)), 500);
            }
        }
        
        // 显示提示信息
        function showToast(message) {
            toast.textContent = message;
            toast.classList.add('show');
            setTimeout(() => toast.classList.remove('show'), 2000);
        }
        
        // 切换页面
        function switchPage(pageId) {
            pages.forEach(page => page.classList.remove('active'));
            document.getElementById(pageId).classList.add('active');
            
            navItems.forEach(item => {
                item.classList.remove('active');
                if (item.dataset.page === pageId) {
                    item.classList.add('active');
                }
            });
            
            apiSelectorContainer.classList.toggle('hidden', pageId !== 'homePage');
            
            // 关闭资源嗅探面板
            sniffPanel.classList.remove('show');
            
            // 当切换到收藏页面时强制刷新
            if (pageId === 'collectionPage') {
                renderCollections();
            }
        }
        
        // 复制到剪贴板
        function copyToClipboard(text) {
            const textarea = document.createElement('textarea');
            textarea.value = text;
            document.body.appendChild(textarea);
            textarea.select();
            document.execCommand('copy');
            document.body.removeChild(textarea);
            showToast('链接已复制');
        }
        
        // 辅助函数：补零
        function padZero(num) {
            return num.toString().padStart(2, '0');
        }
        
        // 增强下载功能 - 确保下载的视频有后缀名
        function downloadVideo() {
            if (!currentVideoUrl) {
                showToast('视频未加载完成');
                return;
            }

            // 生成带后缀的文件名
            const now = new Date();
            const fileName = `黯笙小姐姐视频_${now.getFullYear()}${padZero(now.getMonth()+1)}${padZero(now.getDate())}_${padZero(now.getHours())}${padZero(now.getMinutes())}${padZero(now.getSeconds())}.mp4`;

            // 方法1：使用H5+下载方法（适用于HBuilderX打包的APP）
            if (window.plus) {
                try {
                    // 显示下载进度条
                    downloadProgress.style.display = 'block';
                    progressBar.style.width = '0%';
                    
                    const dtask = plus.downloader.createDownload(
                        currentVideoUrl,
                        { 
                            filename: `_downloads/${fileName}`,
                            timeout: 300,
                            retry: 2
                        },
                        function(d, status) {
                            // 隐藏进度条
                            downloadProgress.style.display = 'none';
                            
                            if (status === 200) {
                                showToast('视频已保存到下载目录');
                            } else {
                                showToast('下载失败: ' + status);
                            }
                        }
                    );
                    
                    // 监听下载进度
                    dtask.addEventListener('statechanged', function(task, status) {
                        switch (task.state) {
                            case 3: // 下载中
                                const progress = Math.floor((task.downloadedSize / task.totalSize) * 100);
                                progressBar.style.width = `${progress}%`;
                                break;
                        }
                    });
                    
                    dtask.start();
                    showToast('开始下载...');
                    return;
                } catch (e) {
                    console.log("5+下载失败:", e);
                    downloadProgress.style.display = 'none';
                }
            }

            // 方法2：直接使用a标签下载（带文件名）
            try {
                const a = document.createElement('a');
                a.href = currentVideoUrl;
                a.download = fileName; // 设置下载文件名
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
                showToast('开始下载视频');
                return;
            } catch (e) {
                console.log("直接下载失败:", e);
            }

            // 方法3：使用Blob下载（适用于现代浏览器）
            try {
                // 显示下载进度条
                downloadProgress.style.display = 'block';
                progressBar.style.width = '0%';
                
                fetch(currentVideoUrl)
                    .then(response => {
                        if (!response.ok) throw new Error('下载失败');
                        const contentLength = response.headers.get('content-length');
                        let loaded = 0;
                        
                        const reader = response.body.getReader();
                        const chunks = [];
                        const total = parseInt(contentLength, 10);
                        
                        function read() {
                            return reader.read().then(({ done, value }) => {
                                if (done) {
                                    return new Blob(chunks);
                                }
                                
                                chunks.push(value);
                                loaded += value.length;
                                const progress = Math.floor((loaded / total) * 100);
                                progressBar.style.width = `${progress}%`;
                                
                                return read();
                            });
                        }
                        
                        return read();
                    })
                    .then(blob => {
                        const url = URL.createObjectURL(blob);
                        const a = document.createElement('a');
                        a.href = url;
                        a.download = fileName;
                        document.body.appendChild(a);
                        a.click();
                        document.body.removeChild(a);
                        
                        // 清理对象URL
                        setTimeout(() => URL.revokeObjectURL(url), 100);
                        showToast('下载完成');
                    })
                    .catch(error => {
                        console.error('下载失败:', error);
                        showToast('下载失败，请复制链接手动下载');
                        copyToClipboard(currentVideoUrl);
                    })
                    .finally(() => {
                        // 隐藏进度条
                        setTimeout(() => {
                            downloadProgress.style.display = 'none';
                        }, 1000);
                    });
                return;
            } catch (e) {
                console.log("Blob下载失败:", e);
                downloadProgress.style.display = 'none';
            }

            // 方法4：打开新窗口（最后的手段）
            try {
                window.open(currentVideoUrl, '_blank');
                showToast('请在浏览器菜单中选择"另存为"下载视频');
                copyToClipboard(currentVideoUrl);
            } catch (e) {
                console.log("新窗口打开失败:", e);
                showToast('下载失败，链接已复制，请手动下载');
                copyToClipboard(currentVideoUrl);
            }
        }
        
        // 设置事件监听
        function setupEventListeners() {
            // 随机按钮
            randomBtn.addEventListener('click', () => {
                const randomIndex = Math.floor(Math.random() * videoApis.length);
                selectApi(videoApis[randomIndex]);
            });
            
            // 下一个视频按钮
            nextVideoBtn.addEventListener('click', loadNextVideo);
            
            // 收藏按钮 - 修复同步问题
            likeBtn.addEventListener('click', async () => {
                isLiked = !isLiked;
                const icon = likeBtn.querySelector('i');
                
                if (isLiked) {
                    icon.className = 'fas fa-heart';
                    likeBtn.classList.add('active');
                    
                    // 尝试从数据库获取缩略图
                    let thumbnail = await getThumbnailFromDB(currentVideoUrl);
                    
                    // 如果没有缩略图，使用占位图
                    if (!thumbnail) {
                        thumbnail = `https://picsum.photos/300/500?random=${Math.floor(Math.random() * 100)}`;
                    }
                    
                    collections.push({
                        name: currentApi ? `${currentApi.name}视频` : "收藏视频",
                        url: currentVideoUrl,
                        thumb: thumbnail,
                        date: new Date().toLocaleString()
                    });
                    localStorage.setItem('collections', JSON.stringify(collections));
                    showToast('已添加到收藏');
                    
                    // 强制刷新收藏页面
                    if (document.getElementById('collectionPage').classList.contains('active')) {
                        renderCollections();
                    }
                    
                    // 尝试捕获缩略图
                    captureThumbnail();
                } else {
                    icon.className = 'far fa-heart';
                    likeBtn.classList.remove('active');
                    
                    collections = collections.filter(item => item.url !== currentVideoUrl);
                    localStorage.setItem('collections', JSON.stringify(collections));
                    showToast('已取消收藏');
                    
                    // 强制刷新收藏页面
                    if (document.getElementById('collectionPage').classList.contains('active')) {
                        renderCollections();
                    }
                }
            });
            
            // 资源嗅探按钮
            sniffBtn.addEventListener('click', () => {
                sniffPanel.classList.toggle('show');
                updateSniffPanel();
            });
            
            // 关闭资源嗅探面板
            sniffClose.addEventListener('click', () => {
                sniffPanel.classList.remove('show');
            });
            
            // 复制资源链接
            sniffCopyBtn.addEventListener('click', () => {
                if (currentVideoUrl) {
                    copyToClipboard(currentVideoUrl);
                }
            });
            
            // 下载资源
            sniffDownloadBtn.addEventListener('click', downloadVideo);
            
            // 分享按钮
            shareBtn.addEventListener('click', () => {
                if (!currentVideoUrl) {
                    showToast('视频未加载完成');
                    return;
                }
                
                const shareText = `黯笙爱看小姐姐：${currentVideoUrl}`;
                
                if (navigator.share) {
                    navigator.share({
                        title: '黯笙爱看小姐姐',
                        text: '分享一个有趣的视频',
                        url: currentVideoUrl
                    }).catch(error => {
                        console.log('分享失败:', error);
                        copyToClipboard(shareText);
                    });
                } else {
                    copyToClipboard(shareText);
                }
            });
            
            // 连播按钮
            autoPlayBtn.addEventListener('click', () => {
                continuousPlay = !continuousPlay;
                document.getElementById('continuousPlay').checked = continuousPlay;
                saveUserSettings();
                
                if (continuousPlay) {
                    autoPlayBtn.classList.add('active');
                    showToast('连续播放已开启');
                } else {
                    autoPlayBtn.classList.remove('active');
                    showToast('连续播放已关闭');
                }
            });
            
            // API选择器点击事件
            compactApiSelector.addEventListener('click', () => {
                apiDropdown.classList.toggle('show');
                compactApiSelector.querySelector('i').classList.toggle('fa-chevron-up');
                compactApiSelector.querySelector('i').classList.toggle('fa-chevron-down');
            });
            
            // API下拉项选择
            document.querySelectorAll('.api-item').forEach(item => {
                item.addEventListener('click', () => {
                    const url = item.dataset.url;
                    const api = videoApis.find(api => api.url === url);
                    if (api) {
                        selectApi(api);
                        apiDropdown.classList.remove('show');
                        compactApiSelector.querySelector('i').classList.add('fa-chevron-down');
                        compactApiSelector.querySelector('i').classList.remove('fa-chevron-up');
                    }
                });
            });
            
            // 导航栏切换
            navItems.forEach(item => {
                item.addEventListener('click', () => switchPage(item.dataset.page));
            });
            
            // 设置变化
            document.getElementById('loopPlay').addEventListener('change', saveUserSettings);
            document.getElementById('autoPlay').addEventListener('change', saveUserSettings);
            document.getElementById('continuousPlay').addEventListener('change', (e) => {
                continuousPlay = e.target.checked;
                saveUserSettings();
                autoPlayBtn.classList.toggle('active', continuousPlay);
            });
            
            // 主题切换
            themeOptions.forEach(option => {
                option.addEventListener('click', () => {
                    themeOptions.forEach(opt => opt.classList.remove('active'));
                    option.classList.add('active');
                    document.body.className = option.dataset.theme;
                    userSettings.currentTheme = option.dataset.theme;
                    saveUserSettings();
                });
            });
            
            // 点击页面其他区域关闭下拉菜单
            document.addEventListener('click', (e) => {
                if (!compactApiSelector.contains(e.target) && !apiDropdown.contains(e.target)) {
                    apiDropdown.classList.remove('show');
                    compactApiSelector.querySelector('i').classList.add('fa-chevron-down');
                    compactApiSelector.querySelector('i').classList.remove('fa-chevron-up');
                }
                
                // 关闭资源嗅探面板
                if (!sniffBtn.contains(e.target) && !sniffPanel.contains(e.target)) {
                    sniffPanel.classList.remove('show');
                }
            });
            
            // 设置组折叠功能
            document.querySelectorAll('.settings-group-header').forEach(header => {
                header.addEventListener('click', function() {
                    const group = this.parentNode;
                    group.classList.toggle('collapsed');
                    saveUserSettings();
                });
            });
            
            // 删除确认对话框
            dialogCancel.addEventListener('click', () => {
                confirmationDialog.classList.remove('show');
            });
            
            dialogConfirm.addEventListener('click', () => {
                if (deleteIndex !== null) {
                    collections.splice(deleteIndex, 1);
                    localStorage.setItem('collections', JSON.stringify(collections));
                    showToast('已删除收藏');
                    confirmationDialog.classList.remove('show');
                    
                    // 强制刷新收藏页面
                    if (document.getElementById('collectionPage').classList.contains('active')) {
                        renderCollections();
                    }
                    
                    // 如果删除的是当前视频，更新收藏状态
                    if (currentVideoUrl === collections[deleteIndex]?.url) {
                        checkIfLiked(currentVideoUrl);
                    }
                    
                    deleteIndex = null;
                }
            });

            // 添加视频播放器点击事件监听
            const videoContainer = document.querySelector('.video-container');
            videoContainer.addEventListener('click', function(e) {
                // 确保点击的不是控制按钮区域
                if (!e.target.closest('.video-actions') && 
                    !e.target.closest('.vjs-control-bar') && 
                    !e.target.closest('.vjs-big-play-button')) {
                    
                    // 切换播放/暂停状态
                    if (player.paused()) {
                        player.play().catch(e => console.log("播放失败:", e));
                    } else {
                        player.pause();
                    }
                }
            });
        }
        
        // 页面加载完成后初始化
        window.addEventListener('DOMContentLoaded', init);
    </script>
</body>
</html>